package easy;

public class offer21_调整数组顺序使奇数位于偶数前面 {
    public int[] exchange(int[] nums) {
        int[] ans = new int[nums.length];
        int left = 0;
        int right = nums.length - 1;
        for (int i = 0; i < nums.length; i++) {
            if (nums[i] % 2 != 0) {
                ans[left] = nums[i];
                left++;
            } else {
                ans[right] = nums[i];
                right--;
            }
        }

        return ans;
    }
}
